//
//  NetworkRetryModel.m
//  NetworkDemo
//
//  Created by 万孟超 on 2021/9/9.
//

#import "NetworkRetryModel.h"

@interface NetworkRetryModel()
//引擎标志
@property (nonatomic, copy) NSString *enginePoint;
//重试的请求Model
@property (nonatomic, strong) NetworkBaseRequest *networkRequest;
//成功回调
@property (nonatomic, copy) CompletionBlock SuccessBlock;
//失败回调
@property (nonatomic, copy) ErrorBlock FailBlock;
//进度回调
@property (nonatomic, copy) ProgressBlock ProgressBlock;

@end

@implementation NetworkRetryModel

/// 初始化Model
/// @param req 请求Model
/// @param enginePoint 引擎标志
/// @param progress 进度回调
/// @param success 成功回调
/// @param errorBlock 失败回调
+ (instancetype)retryModelWithRequest:(NetworkBaseRequest *)req
                          enginePoint:(NSString *)enginePoint
                       isTimeoutRetry:(BOOL)isTimeout
                        progressBlock:(ProgressBlock)progress
                         successBlock:(CompletionBlock)success
                           errorBlock:(ErrorBlock)errorBlock {
    NetworkRetryModel *model = [[NetworkRetryModel alloc] init];
    model.networkRequest = req;
    model.networkRequest.isTimeoutRetry = isTimeout;
    model.enginePoint = enginePoint;
    model.ProgressBlock = progress;
    model.SuccessBlock = success;
    model.FailBlock = errorBlock;
    return model;
}

/// 网络请求回调
- (void)retryNetwork {
    [[NetworkManager defaultManager] POSTWithRequest:self.networkRequest enginePoint:self.enginePoint progressBlock:self.ProgressBlock successBlock:self.SuccessBlock errorBlock:self.FailBlock];
}

@end
